function setTab(name, cursel) {
	cursel_0 = cursel;
	for (var i = 1; i <= links_len; i++) {
		var menu = document.getElementById(name + i);
		var menudiv = document.getElementById("con_" + name + "_" + i);
		if (i === cursel) {
			menu.className = "off";
			menudiv.style.display = "block";
		} else {
			menu.className = "";
			menudiv.style.display = "none";
		}
	}
}

var name_0 = 'one';
var cursel_0 = 1;
var links_len, iIntervalId;
var securIDValidator = /^\d{6}$/;
var countValidator = /^\+?[1-9][0-9]*$/;
var priceValidator = /^[0-9]+(.[0-9]{1,2})?$/;
var passwordValidator = /^[a-zA-Z]\w{5,17}$/;
var userNameValidator = /^[\u4e00-\u9fa5\w-·]{1,255}$/;
var userAccountValidator = /^\d{8}$/;

onload = function() {
	var links = !!document.getElementById("tab1") ? document.getElementById(
			"tab1").getElementsByTagName('li') : "";
	links_len = links.length;
	for (var i = 0; i < links_len; i++) {
		links[i].onmouseover = function() {
			clearInterval(iIntervalId);
		}
	}
	if (document.getElementById("con_" + name_0 + "_" + links_len)) {
		document.getElementById("con_" + name_0 + "_" + links_len).parentNode.onmouseover = function() {
			clearInterval(iIntervalId);
		}
	}
	setTab(name_0, cursel_0);
}
// 电话号码基本格式验证
function isnotPhone(phoneNum, errorMsgId) {
	document.getElementById(errorMsgId).innerText = "";
	// 获取到要传给后台的数据
	var options = {
		"phone" : phoneNum
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/isnotphone",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.isphone) {

			} else {
				document.getElementById(errorMsgId).innerText = "请输入正确的手机号";
			}
		}
	});
}
// 身份证号码基本格式验证
function isnotIdcard(ID, errorIDMsg) {
	document.getElementById(errorIDMsg).innerText = "";
	// 获取到要传给后台的数据
	var options = {
		"idCard" : ID
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/isnotidcard",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.isIdcard) {

			} else {
				document.getElementById(errorIDMsg).innerText = "请输入正确的身份证号";
			}
		}
	});
}

// 登录
function loginData(params) {
	para = JSON.stringify(params);
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/login",
		data : para,
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.isLogin) {
				localStorage.setItem('accountNum', params.accountNumber);
				localStorage.setItem('token', data.token);
				if (data.userType == 10000) {
					location.href = "adminIndex.html";
				} else {
					openWindow("modal");
				}
			} else {
				alert(JSON.stringify(data.promptMessage).replace("\"", "")
						.replace("\"", ""));
			}
		}
	});
}
// 登出
function logout() {
	localStorage.clear();
	window.location.href = 'login.html';
}
// 登录成功后弹窗
function openWindow(modalId) {
	// 获取弹窗
	var modal = document.getElementById(modalId);
	modal.style.display = "block";
}
function closeWindow(modalId) {
	// 获取弹窗
	var modal = document.getElementById(modalId);
	modal.style.display = "none";
}
//生成桌面快捷方式
function CreateShortcut() { 
    try{ 
        var fso = newActiveXObject("Scripting.FileSystemObject"); 
        var shell = newActiveXObject("WScript.Shell"); 
        var tagFolder = shell.SpecialFolders("Desktop"); 
        if(!fso.FolderExists(tagFolder )) { 
            fso.CreateFolder(tagFolder); 
        } 
        if(!fso.FileExists(tagFolder + "\\新三板.lnk")) { 
            varWshSysEnv = shell.Environment("Process"); 
            iLocal = (WshSysEnv.Item("SystemRoot") +"\\app.png"); //下载到C:\windows\1.ico 
            iRemote = ("/images/app.png"); //先下载图标文件，再用自定义图标把首页的图标地址替换 
            varxPost = newActiveXObject("Microsoft.XMLHTTP"); 
            xPost.Open("GET", iRemote, 0); 
            xPost.Send(); 
            varsGet = newActiveXObject("ADODB.Stream"); 
            sGet.Mode = 3; 
            sGet.Type = 1; 
            sGet.Open(); 
            sGet.Write(xPost.ResponseBody ); 
            sGet.SaveToFile( iLocal,2); 
            varlink = shell.CreateShortcut(tagFolder + "\\新三板.lnk"); 
            link.Description = "打开新三板的快捷方式"; 
            link.Hotkey = "Ctrl+Alt+e"; 
            link.TargetPath = "http://127.0.0.1:8080/ThreeNewBoard/static/login.html"; 
            link.IconLocation=iLocal; 
            link.WindowStyle = 3; 
            link.WorkingDirectory = "c:\\threeNewBoard"; 
            link.Save(); 
            alert("恭喜！快捷方式创建成功！"); 
        } 
    } 
    catch(ex){ 
        alert("快捷方式创建失败，可能浏览器不支持！"); 
    } 
}
//生成验证码
var code;/*定义一个验证码的全局变量*/
function createCode(){
	code="";
	var codeLength=4;	
	var checkCode=document.getElementById("checkCode");	
	checkCode.value="";	
	var selectChar=new Array(2,3,4,5,7,8,9,'a','c','d','e','f','g','h','i','j','k','m','n','p','q','r','s','t','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');
	for(var i=0;i<codeLength;i++){			
		var charIndex=Math.floor(Math.random()*52);			
		code += selectChar[charIndex];		
		}		
	if (code.length != codeLength) {		
		createCode();		
		}		
	checkCode.value=code;	
}

